/**
 *
 */
import Util;
import OSS;
import OpenPlatform;
import OSSUtil;
import FileForm;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('videorecog', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model DetectVideoShotRequest {
  videoUrl?: string(name='VideoUrl', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/DetectVideoShot/DetectVideoShot2.mp4'),
}

model DetectVideoShotAdvanceRequest {
  videoUrlObject?: readable(name='VideoUrl', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/DetectVideoShot/DetectVideoShot2.mp4'),
}

model DetectVideoShotResponseBody = {
  data?: {
    shotFrameIds?: [ int32 ](name='ShotFrameIds', description='1'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='0033B795-09C7-4EB9-A33C-EBA325192B0D'),
}

model DetectVideoShotResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: DetectVideoShotResponseBody(name='body'),
}

/**
 * @param request DetectVideoShotRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return DetectVideoShotResponse
 */
async function detectVideoShotWithOptions(request: DetectVideoShotRequest, runtime: Util.RuntimeOptions): DetectVideoShotResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.videoUrl)) {
    body['VideoUrl'] = request.videoUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'DetectVideoShot',
    version = '2020-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request DetectVideoShotRequest
 * @return DetectVideoShotResponse
 */
async function detectVideoShot(request: DetectVideoShotRequest): DetectVideoShotResponse {
  var runtime = new Util.RuntimeOptions{};
  return detectVideoShotWithOptions(request, runtime);
}

async function detectVideoShotAdvance(request: DetectVideoShotAdvanceRequest, runtime: Util.RuntimeOptions): DetectVideoShotResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'videorecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var detectVideoShotReq = new DetectVideoShotRequest{};
  OpenApiUtil.convert(request, detectVideoShotReq);

  if(!Util.isUnset(request.videoUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.videoUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    detectVideoShotReq.videoUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var detectVideoShotResp = detectVideoShotWithOptions(detectVideoShotReq, runtime);
  return detectVideoShotResp;
}

model EvaluateVideoQualityRequest {
  mode?: string(name='Mode', example='vqa_plus'),
  videoUrl?: string(name='VideoUrl', description='This parameter is required.', example='http://public-vigen-video.oss-cn-shanghai.aliyuncs.com/Common/xxx/dont_delete/decaption/123.mp4'),
}

model EvaluateVideoQualityAdvanceRequest {
  mode?: string(name='Mode', example='vqa_plus'),
  videoUrlObject?: readable(name='VideoUrl', description='This parameter is required.', example='http://public-vigen-video.oss-cn-shanghai.aliyuncs.com/Common/xxx/dont_delete/decaption/123.mp4'),
}

model EvaluateVideoQualityResponseBody = {
  data?: {
    jsonUrl?: string(name='JsonUrl', example='http://vibktprfx-prod-prod-damo-eas-cn-shanghai.oss-cn-shanghai.aliyuncs.com/eas-video-quality-assessment/2023-01-13-10/31%3A08-cVeN9ZQlzIPfGqsa.json?Expires=1673578869&amp;OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&amp;Signature=AiSsOsZ7rYfhf9w3Mxn%2Fq4GKKy****'),
    pdfUrl?: string(name='PdfUrl', example='http://vibktprfx-prod-prod-damo-eas-cn-shanghai.oss-cn-shanghai.aliyuncs.com/eas-video-quality-assessment/2023-01-13-10/31%3A08-cVeN9ZQlzIPfGqsa.pdf?Expires=1673578869&amp;OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&amp;Signature=xULlZzVuhoYWAXRbp9A4EzzZcS****'),
    videoQualityInfo?: {
      blurriness?: float(name='Blurriness', example='0.15'),
      colorContrast?: float(name='ColorContrast', example='0.55'),
      colorSaturation?: float(name='ColorSaturation', example='0.17'),
      colorfulness?: float(name='Colorfulness', example='0.48'),
      compressiveStrength?: float(name='CompressiveStrength', example='0.25'),
      luminance?: float(name='Luminance', example='0.51'),
      mosScore?: float(name='MosScore', example='0.7048'),
      noiseIntensity?: float(name='NoiseIntensity', example='0.01'),
    }(name='VideoQualityInfo'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='1d33e538-c949-4fcd-83f6-4d57e4b31527'),
}

model EvaluateVideoQualityResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: EvaluateVideoQualityResponseBody(name='body'),
}

/**
 * @summary 视频质量评估
 *
 * @param request EvaluateVideoQualityRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return EvaluateVideoQualityResponse
 */
async function evaluateVideoQualityWithOptions(request: EvaluateVideoQualityRequest, runtime: Util.RuntimeOptions): EvaluateVideoQualityResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.mode)) {
    body['Mode'] = request.mode;
  }
  if (!Util.isUnset(request.videoUrl)) {
    body['VideoUrl'] = request.videoUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'EvaluateVideoQuality',
    version = '2020-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 视频质量评估
 *
 * @param request EvaluateVideoQualityRequest
 * @return EvaluateVideoQualityResponse
 */
async function evaluateVideoQuality(request: EvaluateVideoQualityRequest): EvaluateVideoQualityResponse {
  var runtime = new Util.RuntimeOptions{};
  return evaluateVideoQualityWithOptions(request, runtime);
}

async function evaluateVideoQualityAdvance(request: EvaluateVideoQualityAdvanceRequest, runtime: Util.RuntimeOptions): EvaluateVideoQualityResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'videorecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var evaluateVideoQualityReq = new EvaluateVideoQualityRequest{};
  OpenApiUtil.convert(request, evaluateVideoQualityReq);

  if(!Util.isUnset(request.videoUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.videoUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    evaluateVideoQualityReq.videoUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var evaluateVideoQualityResp = evaluateVideoQualityWithOptions(evaluateVideoQualityReq, runtime);
  return evaluateVideoQualityResp;
}

model GenerateVideoCoverRequest {
  isGif?: boolean(name='IsGif', description='This parameter is required.', example='false'),
  videoUrl?: string(name='VideoUrl', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/videorecog/videorecog1.mp4'),
}

model GenerateVideoCoverAdvanceRequest {
  isGif?: boolean(name='IsGif', description='This parameter is required.', example='false'),
  videoUrlObject?: readable(name='VideoUrl', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/videorecog/videorecog1.mp4'),
}

model GenerateVideoCoverResponseBody = {
  data?: {
    outputs?: [ 
      {
        confidence?: float(name='Confidence', example='6.1819260887924425'),
        imageURL?: string(name='ImageURL', example='http://algo-app-aic-vd-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/video-cover/2020-05-11-07/pic_lOyxGGAqQYSANGxP.mp4_202_544_960_c9f88b2a5f75e17c093d1a65f5edff4d_beautified.png?Expires=1589185385&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=PAalKsfeZC4UQzYDTU%2F3D1G7Xt****'),
      }
    ](name='Outputs'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='5B95B724-C5B9-4F77-A743-0CA4EA95CC82'),
}

model GenerateVideoCoverResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GenerateVideoCoverResponseBody(name='body'),
}

/**
 * @param request GenerateVideoCoverRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GenerateVideoCoverResponse
 */
async function generateVideoCoverWithOptions(request: GenerateVideoCoverRequest, runtime: Util.RuntimeOptions): GenerateVideoCoverResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.isGif)) {
    body['IsGif'] = request.isGif;
  }
  if (!Util.isUnset(request.videoUrl)) {
    body['VideoUrl'] = request.videoUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GenerateVideoCover',
    version = '2020-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GenerateVideoCoverRequest
 * @return GenerateVideoCoverResponse
 */
async function generateVideoCover(request: GenerateVideoCoverRequest): GenerateVideoCoverResponse {
  var runtime = new Util.RuntimeOptions{};
  return generateVideoCoverWithOptions(request, runtime);
}

async function generateVideoCoverAdvance(request: GenerateVideoCoverAdvanceRequest, runtime: Util.RuntimeOptions): GenerateVideoCoverResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'videorecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var generateVideoCoverReq = new GenerateVideoCoverRequest{};
  OpenApiUtil.convert(request, generateVideoCoverReq);

  if(!Util.isUnset(request.videoUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.videoUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    generateVideoCoverReq.videoUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var generateVideoCoverResp = generateVideoCoverWithOptions(generateVideoCoverReq, runtime);
  return generateVideoCoverResp;
}

model GetAsyncJobResultRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='E75FE679-0303-4DD1-8252-1143B4FA8A27'),
}

model GetAsyncJobResultResponseBody = {
  data?: {
    errorCode?: string(name='ErrorCode', example='InvalidParameter'),
    errorMessage?: string(name='ErrorMessage', example='paramsIllegal'),
    jobId?: string(name='JobId', example='7DFDA846-178B-4ADB-B69A-62C641214D81'),
    result?: string(name='Result', example='{\\\\"Outputs\\\\":[{\\\\"ImageURL\\\\":\\\\"http://algo-app-aic-vd-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/video-cover/2020-03-25-11/pic_4t7zW6R6SUGn4DLF.mp4_2375_1920_1080_96ce5a96b5b16628cd778c035b68356d_beautified.png?Expires=1585136160&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=MDd7BqbivlLRd16MTKbPFQHV3u****\\\\",\\\\"Confidence\\\\":8.426481079120514},{\\\\"ImageURL\\\\":\\\\"http://algo-app-aic-vd-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/video-cover/2020-03-25-11/pic_4t7zW6R6SUGn4DLF.mp4_2996_1920_1080_d5df0556bf420242c84fe6f7a45d01e1_beautified.png?Expires=1585136160&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=htaW5G%2BpqPBW%2BEMTe01ckVoGsQ****\\\\",\\\\"Confidence\\\\":6.225726566341124}]}'),
    status?: string(name='Status', example='PROCESS_SUCCESS'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='A1F44EC4-118D-4A03-B213-F908F36F7DAA'),
}

model GetAsyncJobResultResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetAsyncJobResultResponseBody(name='body'),
}

/**
 * @param request GetAsyncJobResultRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetAsyncJobResultResponse
 */
async function getAsyncJobResultWithOptions(request: GetAsyncJobResultRequest, runtime: Util.RuntimeOptions): GetAsyncJobResultResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetAsyncJobResult',
    version = '2020-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetAsyncJobResultRequest
 * @return GetAsyncJobResultResponse
 */
async function getAsyncJobResult(request: GetAsyncJobResultRequest): GetAsyncJobResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAsyncJobResultWithOptions(request, runtime);
}

model RecognizeVideoCastCrewListRequest {
  params?: [ 
    {
      type?: string(name='Type', example='cast'),
    }
  ](name='Params'),
  videoUrl?: string(name='VideoUrl', description='This parameter is required.', example='https://shanghai.oss-cn-shanghai.aliyuncs.com/download/xxxx.mp4'),
}

model RecognizeVideoCastCrewListAdvanceRequest {
  params?: [ 
    {
      type?: string(name='Type', example='cast'),
    }
  ](name='Params'),
  videoUrlObject?: readable(name='VideoUrl', description='This parameter is required.', example='https://shanghai.oss-cn-shanghai.aliyuncs.com/download/xxxx.mp4'),
}

model RecognizeVideoCastCrewListShrinkRequest {
  paramsShrink?: string(name='Params'),
  videoUrl?: string(name='VideoUrl', description='This parameter is required.', example='https://shanghai.oss-cn-shanghai.aliyuncs.com/download/xxxx.mp4'),
}

model RecognizeVideoCastCrewListResponseBody = {
  data?: {
    castResults?: [ 
      {
        detailInfo?: map[string]string(name='DetailInfo'),
        endTime?: float(name='EndTime', example='0.6'),
        startTime?: float(name='StartTime', example='0.6'),
      }
    ](name='CastResults'),
    ocrResults?: [ 
      {
        detailInfo?: [ 
          {
            boxes?: [ int32 ](name='Boxes'),
            charProbs?: [[ float ]            ](name='CharProbs'),
            frameIndex?: long(name='FrameIndex', example='17'),
            position?: [ 
              {
                x?: long(name='X', example='266'),
                y?: long(name='Y', example='440'),
              }
            ](name='Position'),
            score?: float(name='Score', example='92.07685702563117'),
            text?: string(name='Text'),
            textProb?: float(name='TextProb', example='0.9207685702563116'),
            timeStamp?: float(name='TimeStamp', example='0.28'),
            trackId?: long(name='TrackId', example='1'),
          }
        ](name='DetailInfo'),
        endTime?: float(name='EndTime', example='0.28'),
        startTime?: float(name='StartTime', example='0.28'),
      }
    ](name='OcrResults'),
    ocrResultsUrl?: string(name='OcrResultsUrl', example='http://vibktprfx-prod-prod-media-ai-cn-shanghai.oss-cn-shanghai.aliyuncs.com/video-ocr/1665475907_bGHMygKsFw.json?Expires=1665477707&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=6KQb9OXQldsg30w%2FNurHwAbjiJs%3D'),
    ocrVideoResultsUrl?: string(name='OcrVideoResultsUrl', example='http://vibktprfx-prod-prod-media-ai-cn-shanghai.oss-cn-shanghai.aliyuncs.com/video-ocr/1665475907_VSRvetTHon.json?Expires=1665477707&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=wfQviVVSyVRLPVlHDKXi6cTefHY%3D'),
    subtitlesResults?: [ 
      {
        subtitlesAllResults?: map[string]string(name='SubtitlesAllResults'),
        subtitlesAllResultsUrl?: string(name='SubtitlesAllResultsUrl', example='url'),
        subtitlesChineseResults?: map[string]string(name='SubtitlesChineseResults'),
        subtitlesChineseResultsUrl?: string(name='SubtitlesChineseResultsUrl', example='url1'),
        subtitlesEnglishResults?: map[string]any(name='SubtitlesEnglishResults', example='hello'),
        subtitlesEnglishResultsUrl?: string(name='SubtitlesEnglishResultsUrl', example='url2'),
      }
    ](name='SubtitlesResults'),
    videoOcrResults?: [ 
      {
        detailInfo?: [ 
          {
            boxes?: [ long ](name='Boxes'),
            position?: [ 
              {
                x?: long(name='X', example='269'),
                y?: long(name='Y', example='423'),
              }
            ](name='Position'),
            score?: float(name='Score', example='92.07685702563117'),
            text?: string(name='Text'),
            textType?: long(name='TextType', example='0'),
          }
        ](name='DetailInfo'),
        endTime?: float(name='EndTime', example='0.92'),
        startTime?: float(name='StartTime', example='0.92'),
      }
    ](name='VideoOcrResults'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='EE5B1A95-064F-1C5E-A6FE-FEE0D734A632'),
}

model RecognizeVideoCastCrewListResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RecognizeVideoCastCrewListResponseBody(name='body'),
}

/**
 * @summary 视频OCR
 *
 * @param tmpReq RecognizeVideoCastCrewListRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return RecognizeVideoCastCrewListResponse
 */
async function recognizeVideoCastCrewListWithOptions(tmpReq: RecognizeVideoCastCrewListRequest, runtime: Util.RuntimeOptions): RecognizeVideoCastCrewListResponse {
  Util.validateModel(tmpReq);
  var request = new RecognizeVideoCastCrewListShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.params)) {
    request.paramsShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.params, 'Params', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.paramsShrink)) {
    body['Params'] = request.paramsShrink;
  }
  if (!Util.isUnset(request.videoUrl)) {
    body['VideoUrl'] = request.videoUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RecognizeVideoCastCrewList',
    version = '2020-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 视频OCR
 *
 * @param request RecognizeVideoCastCrewListRequest
 * @return RecognizeVideoCastCrewListResponse
 */
async function recognizeVideoCastCrewList(request: RecognizeVideoCastCrewListRequest): RecognizeVideoCastCrewListResponse {
  var runtime = new Util.RuntimeOptions{};
  return recognizeVideoCastCrewListWithOptions(request, runtime);
}

async function recognizeVideoCastCrewListAdvance(request: RecognizeVideoCastCrewListAdvanceRequest, runtime: Util.RuntimeOptions): RecognizeVideoCastCrewListResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'videorecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var recognizeVideoCastCrewListReq = new RecognizeVideoCastCrewListRequest{};
  OpenApiUtil.convert(request, recognizeVideoCastCrewListReq);

  if(!Util.isUnset(request.videoUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.videoUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    recognizeVideoCastCrewListReq.videoUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var recognizeVideoCastCrewListResp = recognizeVideoCastCrewListWithOptions(recognizeVideoCastCrewListReq, runtime);
  return recognizeVideoCastCrewListResp;
}

model SplitVideoPartsRequest {
  maxTime?: int32(name='MaxTime'),
  minTime?: int32(name='MinTime'),
  template?: string(name='Template'),
  videoUrl?: string(name='VideoUrl', description='This parameter is required.', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/ocr/xxxx.mp4'),
}

model SplitVideoPartsAdvanceRequest {
  maxTime?: int32(name='MaxTime'),
  minTime?: int32(name='MinTime'),
  template?: string(name='Template'),
  videoUrlObject?: readable(name='VideoUrl', description='This parameter is required.', example='https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/ocr/xxxx.mp4'),
}

model SplitVideoPartsResponseBody = {
  data?: {
    elements?: [ 
      {
        beginTime?: float(name='BeginTime', example='10.06'),
        endTime?: float(name='EndTime', example='17.3'),
        index?: long(name='Index', example='1'),
      }
    ](name='Elements'),
    splitVideoPartResults?: [ 
      {
        beginTime?: float(name='BeginTime'),
        by?: string(name='By'),
        endTime?: float(name='EndTime'),
        theme?: string(name='Theme'),
        type?: string(name='Type'),
      }
    ](name='SplitVideoPartResults'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='A00A3C17-61D5-1489-860D-B709F83A7C40'),
}

model SplitVideoPartsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SplitVideoPartsResponseBody(name='body'),
}

/**
 * @summary 视频拆条
 *
 * @param request SplitVideoPartsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SplitVideoPartsResponse
 */
async function splitVideoPartsWithOptions(request: SplitVideoPartsRequest, runtime: Util.RuntimeOptions): SplitVideoPartsResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.maxTime)) {
    body['MaxTime'] = request.maxTime;
  }
  if (!Util.isUnset(request.minTime)) {
    body['MinTime'] = request.minTime;
  }
  if (!Util.isUnset(request.template)) {
    body['Template'] = request.template;
  }
  if (!Util.isUnset(request.videoUrl)) {
    body['VideoUrl'] = request.videoUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SplitVideoParts',
    version = '2020-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 视频拆条
 *
 * @param request SplitVideoPartsRequest
 * @return SplitVideoPartsResponse
 */
async function splitVideoParts(request: SplitVideoPartsRequest): SplitVideoPartsResponse {
  var runtime = new Util.RuntimeOptions{};
  return splitVideoPartsWithOptions(request, runtime);
}

async function splitVideoPartsAdvance(request: SplitVideoPartsAdvanceRequest, runtime: Util.RuntimeOptions): SplitVideoPartsResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'videorecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var splitVideoPartsReq = new SplitVideoPartsRequest{};
  OpenApiUtil.convert(request, splitVideoPartsReq);

  if(!Util.isUnset(request.videoUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.videoUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    splitVideoPartsReq.videoUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var splitVideoPartsResp = splitVideoPartsWithOptions(splitVideoPartsReq, runtime);
  return splitVideoPartsResp;
}

model UnderstandVideoContentRequest {
  videoURL?: string(name='VideoURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/UnderstandVideoContent/UnderstandVideoContent1.mp4'),
}

model UnderstandVideoContentAdvanceRequest {
  videoURLObject?: readable(name='VideoURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/videorecog/UnderstandVideoContent/UnderstandVideoContent1.mp4'),
}

model UnderstandVideoContentResponseBody = {
  data?: {
    tagInfo?: map[string]any(name='TagInfo'),
    videoInfo?: {
      duration?: long(name='Duration', example='43380'),
      fps?: float(name='Fps', example='25.0'),
      height?: long(name='Height', example='1280'),
      width?: long(name='Width', example='720'),
    }(name='VideoInfo'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='71EC3F13-F0CA-4558-AC7F-A351106F59F2'),
}

model UnderstandVideoContentResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: UnderstandVideoContentResponseBody(name='body'),
}

/**
 * @summary 视频内容理解
 *
 * @param request UnderstandVideoContentRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return UnderstandVideoContentResponse
 */
async function understandVideoContentWithOptions(request: UnderstandVideoContentRequest, runtime: Util.RuntimeOptions): UnderstandVideoContentResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.videoURL)) {
    body['VideoURL'] = request.videoURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'UnderstandVideoContent',
    version = '2020-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 视频内容理解
 *
 * @param request UnderstandVideoContentRequest
 * @return UnderstandVideoContentResponse
 */
async function understandVideoContent(request: UnderstandVideoContentRequest): UnderstandVideoContentResponse {
  var runtime = new Util.RuntimeOptions{};
  return understandVideoContentWithOptions(request, runtime);
}

async function understandVideoContentAdvance(request: UnderstandVideoContentAdvanceRequest, runtime: Util.RuntimeOptions): UnderstandVideoContentResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'videorecog',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var understandVideoContentReq = new UnderstandVideoContentRequest{};
  OpenApiUtil.convert(request, understandVideoContentReq);

  if(!Util.isUnset(request.videoURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.videoURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    understandVideoContentReq.videoURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var understandVideoContentResp = understandVideoContentWithOptions(understandVideoContentReq, runtime);
  return understandVideoContentResp;
}

